package core.util;

import org.eclipse.jdt.core.compiler.InvalidInputException;

public class MyCookieValue
{
    private String sessionId;

    private int version;

    private String location;

    public MyCookieValue( String value ) throws InvalidInputException {
        if( value == null || value.length() == 0 || "".equals( value.trim() ) ) {
            throw new InvalidInputException( "value cannot be null or empty" );
        }
        String[] values = value.split( "/" );
        sessionId = values[0];
        version = Integer.valueOf( values[1] );
        location = values[2];
    }

    public MyCookieValue( String sessionId, int version, String location ) {
        this.sessionId = sessionId;
        this.version = version;
        this.location = location;
    }

    public String getSessionId() {
        return sessionId;
    }

    public int getVersion() {
        return version;
    }

    public void increaseVersion() {
        version++;
    }

    public String getLocation() {
        return location;
    }

    @Override
    public String toString() {
        return sessionId + "/" + version + "/" + location;
    }

    @Override
    public boolean equals( Object obj ) {
        if( this == obj )
            return true;
        if( obj == null )
            return false;
        if( getClass() != obj.getClass() )
            return false;
        MyCookieValue other = (MyCookieValue) obj;
        if( location == null ) {
            if( other.location != null )
                return false;
        } else if( !location.equals( other.location ) )
            return false;
        if( sessionId == null ) {
            if( other.sessionId != null )
                return false;
        } else if( !sessionId.equals( other.sessionId ) )
            return false;
        if( version != other.version ) {
            return false;
        }
        return true;
    }

}
